﻿using System.Web.Mvc;

namespace CodeContrib.Web.Mvc.Html
{
	public static class ImageExtensions
	{
		public static MvcHtmlString Image(this HtmlHelper htmlHelper, string url)
		{
			return Image(htmlHelper, url, null);
		}

		public static MvcHtmlString Image(this HtmlHelper htmlHelper, string url, string alternateText)
		{
			Guard.NotNull(url, "url");

			var image = new TagBuilder("img");

			if (!string.IsNullOrEmpty(alternateText))
			{
				image.Attributes["alt"] = alternateText;
			}

			image.Attributes["src"] = url;

			return MvcHtmlString.Create(image.ToString(TagRenderMode.SelfClosing));
		}
	}
}